/**
 * 
 */
package org.mspring.crm.server;

import javax.servlet.http.HttpServletRequest;

import org.mspring.crm.client.common.CommonTokens;
import org.mspring.crm.client.model.UserModel;
import org.mspring.crm.client.remote.UserRemote;
import org.mspring.crm.entity.permission.User;
import org.mspring.crm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Gao Youbo
 * @since 2012-3-7
 * 
 */
@Service("userRemote")
public class UserRemoteImpl extends BaseRemote implements UserRemote {

    /**
     * 
     */
    private static final long serialVersionUID = -3828115758444816315L;
    private UserService userService;

    @Autowired
    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * org.mspring.crm.client.remote.UserRemote#validateUser(java.lang.String,
     * java.lang.String)
     */
    @Override
    public UserModel validateUser(String username, String password) {
        // TODO Auto-generated method stub
        User user = userService.validateUser(username, password);
        if (user != null) {
            UserModel userModel = convertToModel(user);
            // HttpServletRequest request = getThreadLocalRequest();
            // request.getSession().setAttribute(CommonTokens.SESSION_LOGINUSER,
            // user);
            // request.getSession().setAttribute(CommonTokens.SESSION_LOGINUSER_MODEL,
            // userModel);
            return userModel;
        }
        return null;
    }

}
